<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html dir="ltr" xmlns="http://www.w3.org/1999/xhtml">
<%@include file="/WEB-INF/taglibs/common/taglibs.jsp"%>
<head>
<title><spring:message code="admin.viewlicenseapplication.title" /></title>
<meta content="text/html; charset=utf-8" http-equiv="Content-Type" />
<link rel="stylesheet" href="<c:url value="/css/styles.css"/>" />
<script src="<c:url value="/javascripts/common.js"/>" type="text/javascript"></script>
<script language="javascript" type="text/javascript">
    var f = null;
    var ALL_TRUE  = [true,true,true,true,true,true,true];
    var ALL_FALSE = [false,false,false,false,false,false,false];
    var cols  = ['id','silentCreation','silentUpdate','announceLinkOnNewsPage','mandatoryAtNewRegistration','mandatoryAtNextLogin','mandatoryBeforeNextOrder'];
    var idCol = cols[0];
    var totalRows = 0;
         
	function initPage(){
		f = document.f1;
		setData();		 
    }
     
	function selectAll(flag) {
		  
		 for(var i=0;i<totalRows;i++){
			 selectRow( i , (flag)?ALL_TRUE:ALL_FALSE );
		    }
	}
	
	function selectRow(index,flags) { 
		 
		for(var i=0;i<cols.length;i++){
			var name = 'licenseRoleApplyList['+index+'].'+cols[i];
			var idColName = 'licenseRoleApplyList['+index+'].'+idCol;
		 
			f[name].checked = flags[i];

			var disabled = !f[idColName].checked;
			
			if(i>0)
			  {f[name].disabled =  disabled;
			   //var hidden1 = 'licenseRoleApplyList['+index+'].licenseId';
			   //var hidden2 = 'licenseRoleApplyList['+index+'].roleId';
			   //f[hidden1].disabled = f[hidden2].disabled =  disabled;
			  
			  }

			  

			  
		}
	}

	function selectRowById(id,_flags) {
		var cbx = document.getElementById(id);
		var index = parseInt(cbx.getAttribute('rowNum'));
		
		if(!_flags)
		  {var _flags = (cbx.checked?ALL_TRUE:ALL_FALSE); }
		
		selectRow(index,_flags);
	}
	 
    
	function selectCol(flag, colName , forceCheck) { 
		var ch = flag || false;
		 
		for (var i=0;i<totalRows;i++) { 
			var name      = 'licenseRoleApplyList['+i+'].'+colName;
			var idColName = 'licenseRoleApplyList['+i+'].'+idCol; 
            var isAllowed = (forceCheck)?true:f[idColName].checked;
            
            f[name].checked = (isAllowed)?ch:false; 
		}
		return false;
}
	</script>
</head>

<body onload="initPage();"><%@include file="../top_menu.jsp"%>

<%@include file="/WEB-INF/jsp/include/header.jsp"%>
<table width=100%>
	<tr>
		<td><c:import url="/WEB-INF/jsp/menu/admin_license_menu.jsp" /></td>
	</tr>
	<tr>
		<td><%@include file="/WEB-INF/jsp/include/messages.jsp"%>
		<br />
		</td>
	</tr>
</table>
<form action="view_license_applications.htm" name="f1" method="post">
<table width=90% class="formTable">

	<tr class="formHeader">
		<td colspan="11"><spring:message code="admin.viewlicenseapplication.label.licenseapplications" /></td>
	</tr>
				<tr align="center">
					<td><input type="checkbox" onclick="selectAll(this.checked)" /></td>
					<td><br />
					<spring:message code="admin.viewlicenseapplication.label.id" /></td>
					<td><br />
					<spring:message code="admin.viewlicenseapplication.label.role" /></td>
					<td><br />
					<spring:message code="admin.viewlicenseapplication.label.licensename" /></td>
					<td><br />
					<spring:message code="admin.viewlicenseapplication.label.licenseid" /></td>
					<td><input type="checkbox"
						onclick="selectCol(this.checked,'silentCreation')" /><br />
					<spring:message code="admin.viewlicenseapplication.label.silentcreation" />n</td>
					<td><input type="checkbox"
						onclick="selectCol(this.checked,'silentUpdate')" /><br />
					<spring:message code="admin.viewlicenseapplication.label.silentupdate" /></td>
					<td><input type="checkbox"
						onclick="selectCol(this.checked,'announceLinkOnNewsPage')" /><br />
					<spring:message code="admin.viewlicenseapplication.label.announcelinkonnews" /></td>
					<td><input type="checkbox"
						onclick="selectCol(this.checked,'mandatoryAtNewRegistration')" /><br />
					<spring:message code="admin.viewlicenseapplication.label.mandatoryatnewregistration" /></td>
					<td><input type="checkbox"
						onclick="selectCol(this.checked,'mandatoryAtNextLogin')" /><br />
					<spring:message code="admin.viewlicenseapplication.label.mandatoryatnextlogin" /></td>
					<td><input type="checkbox"
						onclick="selectCol(this.checked,'mandatoryBeforeNextOrder')" /><br />
					<spring:message code="admin.viewlicenseapplication.label.mandatorybeforenextorder" /></td>
				</tr>
	 
			<tbody>
				<c:if test="${empty licenseList}">
					<tr>
						<td colspan="11"><spring:message code="admin.viewlicenseapplication.label.nolicencsewerefound" /></td>
					</tr>
				</c:if>

				<c:set var="rowNum" value="0"/>
				<c:forEach var="r" items="${roleList}" varStatus="i">
					<c:forEach var="l" items="${licenseList}" varStatus="j">
						<tr class="tr_record" align="center">
							<td align="center"><input type="checkbox"
								name="licenseRoleApplyList[${rowNum}].id" id="l${l.id}_r${r.id}" rowNum="${rowNum}" value="0" onclick="selectRowById(this.id)" /></td>
							<td>${r.id}</td>
							<td><a
								href="<c:url value="/admin/role/edit_role.htm?id=${r.id}"/>">${r.name}</a><input
								type="hidden" name="licenseRoleApplyList[${rowNum}].roleId"
								value="${r.id}" /></td>
							<td><a
								href="<c:url value="/admin/license/edit_license.htm?id=${l.id}"/>">${l.name}</a><input
								type="hidden" name="licenseRoleApplyList[${rowNum}].licenseId"
								value="${l.id}" /></td>
							<td align='right'>${l.id}</td>
                            <td><input type="checkbox" name="licenseRoleApplyList[${rowNum}].silentCreation" disabled></td>
                            <td><input type="checkbox" name="licenseRoleApplyList[${rowNum}].silentUpdate" disabled></td>
                            <td><input type="checkbox" name="licenseRoleApplyList[${rowNum}].announceLinkOnNewsPage" disabled></td>
                            <td><input type="checkbox" name="licenseRoleApplyList[${rowNum}].mandatoryAtNewRegistration" disabled></td>
                            <td><input type="checkbox" name="licenseRoleApplyList[${rowNum}].mandatoryAtNextLogin" disabled></td>
                            <td><input type="checkbox" name="licenseRoleApplyList[${rowNum}].mandatoryBeforeNextOrder" disabled></td>
                        </tr>

						<c:set var="rowNum" value="${rowNum + 1}"/>
					</c:forEach>
				</c:forEach>
				<tr>
					<td colspan="11"><input type="submit" class='ui-button ui-state-default ui-corner-all' value="<spring:message code="admin.viewlicenseapplication.button.save" />" /></td>
				</tr>
			</tbody>
		</table>
		</form>

<script language="javascript" type="text/javascript"><!--
totalRows = ${rowNum};
function setData(){
<c:forEach var="lr"  items="${licenseRoleApplyList}">
  setRecord(${lr.id},${lr.licenseId},${lr.roleId},[false , ${lr.silentCreation},${lr.silentUpdate},${lr.announceLinkOnNewsPage},${lr.mandatoryAtNewRegistration},${lr.mandatoryAtNextLogin},${lr.mandatoryBeforeNextOrder}]);
</c:forEach> 
}

function setRecord(id,licenseId,roleId , flags ){
 var domId = 'l'+licenseId+'_r'+roleId;
 document.getElementById(domId).value = id;

 // auto check only if at least one flag is set to 'true'
 for(var i=1;i<flags.length;i++){
        if(flags[i]==true)
          {flags[0] = true;
           break;
          } 
	}
 selectRowById( domId , flags);
 //flags silentCreation,silentUpdate,announceLinkOnNewsPage,mandatoryAtNewRegistration,mandatoryAtNextLogin,mandatoryBeforeNextOrder	
}
 
--></script><%@include file="/WEB-INF/jsp/include/footer.jsp"%>
</body>
</html>